package com.htjx.mall.controllers;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.htjx.mall.commons.api.Result;
import com.htjx.mall.commons.models.product.Brand;
import com.htjx.mall.commons.models.product.Category;
import com.htjx.mall.controllers.commonapi.AboutUs;
import com.htjx.mall.services.BrandService;
import com.htjx.mall.services.CategoryService;

@Controller
@RequestMapping("/common")
public class CommonController {
	@Autowired
	private CategoryService categoryService;
	@Autowired
	private BrandService brandService;
	
	@RequestMapping(value = "/catagory", method = RequestMethod.GET, produces = "application/json")
	@ResponseBody
	public Result catagory() {
		List<Category> category = categoryService.selectByActive(true);
		
		Result result = new Result(0, "查询catagory 种类");
		result.setBody(category);
		return result;
	}
	
	@RequestMapping(value = "/brand", method = RequestMethod.GET, produces = "application/json")
	@ResponseBody
	public Result brand() {
		List<Brand> brand = brandService.selectByActive(true);
		
		Result result = new Result(0, "查询brand 种类");
		result.setBody(brand);
		return result;
	}
	
	@RequestMapping(value = "/aboutus", method = RequestMethod.GET, produces = "application/json")
	@ResponseBody
	public Result site() {
		Result result = new Result(0, "查询网站信息");
		result.setBody(new AboutUs());
		return result;
	}
	
	@RequestMapping(value = "/title", method = RequestMethod.GET, produces = "application/json")
	@ResponseBody
	public Result getTitle() {
		Result result = new Result(0, "查询网站信息");
		result.setBody((new AboutUs()).title);
		return result;
	}
}
